package com.handpay.nocardpay.baselibrary.permission;

import android.content.Context;

import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionListener;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;

import java.util.List;


/**
 * Created by sxshi on 2017/8/10.
 * 对权限的统一封装
 */

public class PermissionRequest {
    private Context mContext;
    private onPermissionRequestCallBack mCallback;

    public void setOnPermissionCallBack(onPermissionRequestCallBack mCallback) {
        this.mCallback = mCallback;
    }

    public PermissionRequest(Context mContext) {
        this.mContext = mContext;
    }

    public PermissionRequest(Context mContext, onPermissionRequestCallBack mCallback) {
        this.mContext = mContext;
        this.mCallback = mCallback;
    }

    /**
     * 同一个界面单个权限判断建议使用
     * @param permission
     */
    public void requestPermission(String[]... permission) {
        AndPermission.with(mContext)
                .requestCode(PermissionCode.DEFAULT_PERMISSION_CODE)
                .permission(permission)
                .callback(this)
                .start();
    }

    /**
     * 同一个界面多个权限检测调用
     * 详情
     * {@link com.handpay.nocardpay.baselibrary.qualificationinfo.view.fragment.QualificationPictureInfoFragment }
     * @param requestCode
     * @param listener
     * @param permison
     */
    public void requestPermission(int requestCode, PermissionListener listener, String[]... permison) {
        AndPermission.with(mContext)
                .requestCode(requestCode)
                .permission(permison)
                .callback(listener)
                .start();
    }

    @PermissionYes(PermissionCode.DEFAULT_PERMISSION_CODE)
    public void permissionYes(List<String> permissions) {
        this.mCallback.permissionYes(permissions);
    }


    @PermissionNo(PermissionCode.DEFAULT_PERMISSION_CODE)
    public void permissionFail(List<String> permissions) {
        this.mCallback.permissionFail(permissions);
    }


    public interface onPermissionRequestCallBack {
        void permissionYes(List<String> permissions);

        void permissionFail(List<String> permissions);
    }
}
